package com.dragon.aipictures.test2;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class ShardMetadataService {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    
    public ShardMetadata getMetadata(Long spaceId) {
        return jdbcTemplate.queryForObject(
            "SELECT * FROM sharding_metadata WHERE space_id = ?",
            (rs, rowNum) -> {
                ShardMetadata metadata = new ShardMetadata();
                metadata.setSpaceId(rs.getLong("space_id"));
                metadata.setTableCount(rs.getInt("table_count"));
                metadata.setStatus(rs.getString("status"));
                metadata.setVersion(rs.getInt("version"));
                return metadata;
            },
            spaceId
        );
    }

    public void updateStatus(Long spaceId, String status) {
        jdbcTemplate.update(
            "UPDATE sharding_metadata SET status = ? WHERE space_id = ?",
            status, spaceId
        );
    }
}